package tuan.score;

import java.util.*;

import org.w3c.dom.*;

public class NodeScoreChain {

	List<NodeScore> scoreList = new ArrayList<NodeScore>();

	public void setScore(List<Node> nodeList) throws Exception {
		if (nodeList == null) {
			throw new Exception("null arguments");
		}
		
		Iterator<Node> iter = nodeList.iterator();
		while (iter.hasNext()) {
			Node node = iter.next();
			node.setUserData("score", 0.0, null);
			for (NodeScore score : scoreList) {
				double s = (Double) node.getUserData("score");
				s += score.getScore(node);
				node.setUserData("score", s, null);
			}
		}
	}

	public void addScore(NodeScore score) throws Exception {
		if (score == null) {
			throw new Exception("null arguments");
		}
		scoreList.add(score);
	}

}
